#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<time.h>
#include<stdlib.h>

void Swap(int* p1, int* p2)
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

void QuickSort(int* a, int left, int right)
{
	if (left >= right)
	{
		return;
	}
	int randi = left + (rand() % (right - left + 1));
	if (randi != left)
	{
		Swap(&a[left],&a[randi]);
	}
	int keyi = left;
	int prev = left;
	int cur = left + 1;
	while (cur <= right)
	{
		if (a[prev] > a[cur] && prev < cur)
		{
			Swap(&a[prev], &a[cur]);
		}
		cur++;
	}
	Swap(&a[keyi], &a[prev]);
	keyi = prev;
	QuickSort(a, left, keyi - 1);
	QuickSort(a, keyi + 1, right);
	
}

int main()
{
	srand(time(NULL));
	int a[] = { 9,8,6,4,3,8,1,5,4,3,-6,-8,-4,-6,-1 };
	int len = sizeof(a) / sizeof(int);
	QuickSort(a, 0, len - 1);
	for (int i = 0; i < len; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");


}